package com.itheima.ydd.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.ydd.common.PageReturn;
import com.itheima.ydd.common.ResultData;
import com.itheima.ydd.entity.YddTag;
import com.itheima.ydd.mapper.YddTagMapper;
import com.itheima.ydd.service.IYddTagService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 */
@Service
public class YddTagServiceImpl extends ServiceImpl<YddTagMapper, YddTag> implements IYddTagService {

    @Override
    public ResultData getPage(String tagename, Integer page1, Integer pageSize) {

        Page<YddTag> pageInfo = new Page<>(page1, pageSize);
        //条件查询
        LambdaQueryWrapper<YddTag> wrapper = new LambdaQueryWrapper<>();
        //模糊查询
        wrapper.like(StringUtils.isNotEmpty(tagename),YddTag::getTagname, tagename);
        //排序
        wrapper.orderByDesc(YddTag::getId);
        pageInfo = page(pageInfo, wrapper);

        PageReturn<YddTag> page=new PageReturn<>();

        page.setData(pageInfo.getRecords());
        page.setCurrentPage(pageInfo.getCurrent());
        page.setPageSize(pageInfo.getSize());
        page.setTotalPages(pageInfo.getPages());
        page.setCount(pageInfo.getTotal());

        return ResultData.ok("", page);

    }
}
